#include<bits/stdc++.h>
using namespace std;
const int y=1e5 + 1;
const int yy=1e6 + 2;
struct pp
{
    long long lft,rgt,id;
    bool operator < (pp a)
    {
        return (rgt==a.rgt)?(lft<a.lft):(rgt>a.rgt);
    }
}sq[y];
long long p[y],pos[y],asp[y],sp[y];
int g[y],h[y];
//int ll[yy];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    sq[0].lft=sq[0].rgt=0;
    h[0]=-1;
    while(t--)
    {
        long long n,m,l,k;
        bool flag=false;
        cin>>n>>m>>l>>k;
        g[0]=m+2;
//        for(int i=0;i<=l;i++) ll[i]=0;
        int t=0;
        for(int i=1;i<=n;i++)
        {
            //long long pos,asp,sp;
            cin>>pos[i]>>sp[i]>>asp[i];
        }
        for(int i=1;i<=m;i++) cin>>p[i];
        for(int i=1;i<=n;i++)
        {
            if((sp[i]<=k)&&(asp[i]<=0)) continue;
            if(asp[i]*2*(l-pos[i])+sp[i]*sp[i]<=k*k) continue;
            if(asp[i]==0)
            {
                t++;
                sq[t].lft=-1;sq[t].rgt=l+1;h[t]=m+1;g[t]=0;
                flag=true;
                continue;
            }
            if(asp[i]<0)
            {
                t++;
                if((k*k-sp[i]*sp[i])%(asp[i]*2)==0) sq[t].rgt=(k*k-sp[i]*sp[i])/(asp[i]*2)+pos[i]-1;
                else sq[t].rgt=(k*k-sp[i]*sp[i])/(asp[i]*2);
                sq[t].lft=pos[i];
                g[t]=lower_bound(p+1,p+m+1,sq[t].lft)-p,h[t]=lower_bound(p+1,p+m+1,sq[t].rgt)-p;
                if((g[t]<=0)&&(h[t]>0)) continue;
                if((h[t]>m)&&(g[t]<=m)) continue;
                if(h[t]<=0)
                {
                    t--;continue;
                }
                if(g[t]>m)
                {
                    t--;continue;
                }
                if((p[g[t]]>sq[t].lft)&&(p[h[t]]>sq[t].rgt)&&(g[t]==h[t])) t--;
                continue;
            }
            if(asp[i]>0)
            {
                t++;
                sq[t].lft=max(l,(k*k-sp[i]*sp[i])/(asp[i]*2)+pos[i]+1);
                sq[t].rgt=l+1;
                g[t]=lower_bound(p+1,p+m+1,sq[t].lft)-p,h[t]=lower_bound(p+1,p+m+1,sq[t].rgt)-p;
                if((g[t]<=0)&&(h[t]>0)) continue;
                if((h[t]>m)&&(g[t]<=m)) continue;
                if(h[t]<=0)
                {
                    t--;continue;
                }
                if(g[t]>m)
                {
                    t--;continue;
                }
                if((p[g[t]]>sq[t].lft)&&(p[h[t]]>sq[t].rgt)&&(g[t]==h[t])) t--;
                continue;
            }
        }
        for(int i=0;i<=t;i++) sq[i].id=i;
        for(int i=1;i<=t;i++)
        {
            if(((h[i])<=m)&&(p[i]!=sq[i].rgt)) h[i]--;
        }
            sort(sq+1,sq+t+1);
            int rpos=sq[1].id,li=1;
            int cnt=0;
            while(li<=t)
            {
                while((h[rpos]>=g[sq[li].id])&&(g[rpos]<=h[sq[li].id])&&(li<=t))
                {
                    if(g[rpos]>g[sq[li].id]) rpos=g[sq[li].id];
                    li++;
                }
                if(li>t)
                {
                    cnt++;break;
                }
                cnt++;
                rpos=sq[li].id;
            }
            if(flag=true) cout<<n-t<<' '<<max((long long)1,m-cnt);
            else cout<<n-t<<' '<<m-cnt<<endl;
    }
    return 0;
}
